/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attence;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutySystem;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Service("dutysystemService")
public class DutySystemServiceImpl implements DutySystemService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of DutySystem
     ****************************************/
    public void insert(DutySystem dutysystem) throws Exception {
        dutysystem.setSystemid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(dutysystem);
    }

    /****************************************
     * Update a instace of DutySystem
     ****************************************/
    public void update(DutySystem dutysystem) throws Exception {
        iDataSet4iBatis.update(dutysystem);
    }

    /****************************************
     * Delete a instace of DutySystem
     ****************************************/
    public void delete(DutySystem dutysystem) throws Exception {
        iDataSet4iBatis.delete(dutysystem);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(DutySystem dutysystem) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(DutySystem dutysystem) throws Exception {
        String statementId = dutysystem.getStatmentId();
        String mainId = dutysystem.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> dutysystemList = new ArrayList<BaseModel>();
        for (String id : ids) {
            DutySystem model = new DutySystem();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            dutysystemList.add(model);
        }
        iDataSet4iBatis.batchDelete(dutysystemList);
    }

    /****************************************
     * Query instaces of DutySystem
     ****************************************/
    public List<BaseModel> queryAsList(DutySystem dutysystem) throws Exception {
        String queryListStatement = "";
        if (dutysystem.isPaging()) {
            queryListStatement = dutysystem.getStatmentId();
            dutysystem.setStatmentId("DutySystem.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(dutysystem);
            dutysystem.setTotalCount(baseModel.getTotalCount());
            dutysystem.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(dutysystem);
    }

    /****************************************
     * Query a instaces of DutySystem
     ****************************************/
    public BaseModel queryAsObject(DutySystem dutysystem) throws Exception {
        return iDataSet4iBatis.queryAsObject(dutysystem);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
